package com.yuntsg.ruiijn.controller.admin;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@Controller
@RequestMapping("adm_sys")
public class AdminSysController {


    @GetMapping("power_off")
    public void power_off() {
        executeLinuxCmd(" poweroff");
    }

    public void executeLinuxCmd(String cmd) {
        System.out.println("got cmd job : " + cmd);
        Runtime run = Runtime.getRuntime();
        try {
            Process process = run.exec(cmd);
            InputStream in = process.getInputStream();
            BufferedReader bs = new BufferedReader(new InputStreamReader(in));
            in.close();

            process.destroy();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
